<html lang="zh_CN">
{% include "common/table_page_head.html" %}
<body>
<div style="padding: 5px; width: 100%; position: relative; height: 35px;">
    <div style='float:left; height: 30px; margin-right: 5px;'>
        <button class="layui-btn layui-btn-sm layui-btn-disabled" id="viewbtn">
            <i class="layui-icon">&#xe705;</i>&nbsp;查看
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-disabled" id="downbtn">
            <i class="layui-icon">&#xe601;</i>&nbsp;下载
        </button>
        <button class="layui-btn layui-btn-sm" onclick="doQuery()">
            <span class='glyphicon glyphicon-repeat'></span>&nbsp;刷新
        </button>
    </div>
    <div class='input-group input-group-sm'
         style='float:left; width:280px; height: 30px; margin-left: 5px;'>
        <input type="text" id="query_text" placeholder="快速查询..."
               class='form-control'>
        <span class='input-group-btn'>
            <button class='btn btn-default' onclick="doQuery()">
                <span class='glyphicon glyphicon-search'></span>查询
            </button>
        </span>
    </div>
</div>
<table lay-filter="datalist" class="layui-table"
       lay-data="{height:'full-60', page:true,even:true, id:'datalist'}" id="datalist">
    <thead>
    <tr>
        <th lay-data="{field:'sid',hide:true}"></th>
        <th lay-data="{field:'sfileid',hide:true}"></th>
        <th lay-data="{field:'no',width:60}">序号</th>
        <th lay-data="{field:'sfilename'}">名称</th>
        <th lay-data="{field:'sfilesize',width:150}">大小</th>
        <th lay-data="{field:'screatorname',width:100}">上传人员</th>
        <th lay-data="{field:'screatetime', width:160}">上传时间</th>
    </tr>
    </thead>
</table>
</body>
<script type="text/javascript">
    let currentRow = {};

    function doQuery() {
        let search_text = $("#query_text").val();
        let surl = '/system/personal/docnode/docDataList?search_text=' + J_u_encode(search_text);
        surl += "&shared=true";
        currentRow = {};
        layui.table.reload('datalist', {
            url: surl,
            done: function () {//res, curr, count
                $("#search_text").val(search_text);
                changeButton();
            }
        });
    }

    $(document).ready(function () {
        doQuery();
    });


    //触发行单击事件
    layui.table.on('row(datalist)', function (obj) {
        //console.log(obj.tr) //得到当前行元素对象
        //console.log(obj.data) //得到当前行数据
        obj.tr.parent().find('tr').removeClass('active')
        obj.tr.addClass('active') //选中行加特殊背景颜色
        currentRow = obj.data;
        changeButton();
    });

    function changeButton() {
        let viewbtn = $("#viewbtn");
        let downbtn = $("#downbtn");
        if (currentRow.sid) {
            viewbtn.removeClass("layui-btn-disabled");
            J$("viewbtn").onclick = viewFile;
            downbtn.removeClass("layui-btn-disabled");
            J$("downbtn").onclick = downloadFile;
        } else {
            viewbtn.addClass("layui-btn-disabled");
            J$("viewbtn").onclick = null;
            downbtn.addClass("layui-btn-disabled");
            J$("downbtn").onclick = null;
        }
    }

    function viewFile() {
        tlv8.viewFile(currentRow.sfileid, currentRow.sfilename);
    }

    function downloadFile() {
        tlv8.downloadFile(currentRow.sfileid);
    }
</script>
</html>